package com.ruoyi.web.controller.document;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.document.domain.Currency;
import com.ruoyi.document.service.ICurrencyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 币种名称管理Controller
 * 
 * @author ruoyi
 * @date 2023-03-04
 */
@RestController
@RequestMapping("/document/currency")
public class CurrencyController extends BaseController
{
    @Autowired
    private ICurrencyService currencyService;

    /**
     * 前端下拉列表展示的数据
     */
    @GetMapping("/selectCurrencyData")
    public TableDataInfo selectCurrencyData(Currency currency)
    {
        List<Currency> list = currencyService.selectCurrencyList(currency);
        return getDataTable(list);
    }
    /**
     * 查询币种名称管理列表
     */
    @PreAuthorize("@ss.hasPermi('document:currency:list')")
    @GetMapping("/list")
    public TableDataInfo list(Currency currency)
    {
        startPage();
        List<Currency> list = currencyService.selectCurrencyList(currency);
        return getDataTable(list);
    }
    /**
     * 导出币种名称管理列表
     */
    @PreAuthorize("@ss.hasPermi('document:currency:export')")
    @Log(title = "币种名称管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Currency currency)
    {
        List<Currency> list = currencyService.selectCurrencyList(currency);
        ExcelUtil<Currency> util = new ExcelUtil<Currency>(Currency.class);
        util.exportExcel(response, list, "币种名称管理数据");
    }

    /**
     * 获取币种名称管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('document:currency:query')")
    @GetMapping(value = "/{currencyId}")
    public AjaxResult getInfo(@PathVariable("currencyId") Integer currencyId)
    {
        return success(currencyService.selectCurrencyByCurrencyId(currencyId));
    }

    /**
     * 新增币种名称管理
     */
    @PreAuthorize("@ss.hasPermi('document:currency:add')")
    @Log(title = "币种名称管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Currency currency)
    {
        return toAjax(currencyService.insertCurrency(currency));
    }

    /**
     * 修改币种名称管理
     */
    @PreAuthorize("@ss.hasPermi('document:currency:edit')")
    @Log(title = "币种名称管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Currency currency)
    {
        return toAjax(currencyService.updateCurrency(currency));
    }

    /**
     * 删除币种名称管理
     */
    @PreAuthorize("@ss.hasPermi('document:currency:remove')")
    @Log(title = "币种名称管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{currencyIds}")
    public AjaxResult remove(@PathVariable Integer[] currencyIds)
    {
        return toAjax(currencyService.deleteCurrencyByCurrencyIds(currencyIds));
    }
}
